// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   DataSerie.java

package com.java4less.rchart;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Vector;

// Referenced classes of package com.java4less.rchart:
//			Chart, Axis

public class DataSerie
{

	Vector xData;
	Vector yData;
	public Vector hotAreas;
	public String dataLabels[];
	public String name;
	public String valueFormat;
	public String labelTemplate;
	public boolean secondYAxis;
	public double nullValue;
	public Axis secondaryXAxis;
	public Axis secondaryYAxis;
	public String tips[];
	public String htmlLinks[];

	public DataSerie()
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
	}

	public DataSerie(double x[], double y[])
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		for (int i = 0; i < x.length; i++)
			addData(new Double(x[i]), new Double(y[i]));

	}

	public DataSerie(double y[])
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		if (y == null)
			return;
		for (int i = 0; i < y.length; i++)
			addData(new Double(i), new Double(y[i]));

	}

	public DataSerie(Double y[])
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		if (y == null)
			return;
		for (int i = 0; i < y.length; i++)
			addData(new Double(i), y[i]);

	}

	public DataSerie(double y[], int startingXValue)
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		for (int i = 0; i < y.length; i++)
			addData(new Double(startingXValue + i), new Double(y[i]));

	}

	public DataSerie(Double y[], int startingXValue)
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		for (int i = 0; i < y.length; i++)
			addData(new Double(startingXValue + i), y[i]);

	}

	public DataSerie(Double x[], Double y[])
	{
		xData = new Vector(0, 5);
		yData = new Vector(0, 5);
		hotAreas = new Vector(0, 5);
		name = "";
		valueFormat = "######.##";
		labelTemplate = "";
		secondYAxis = false;
		nullValue = -9D;
		secondaryXAxis = null;
		secondaryYAxis = null;
		tips = new String[0];
		htmlLinks = new String[0];
		for (int i = 0; i < x.length; i++)
			addData(x[i], y[i]);

	}

	public void addData(Object x, Object y)
	{
		xData.addElement(x);
		yData.addElement(y);
	}

	public int getSize()
	{
		return xData.size();
	}

	public void setDatax(double x[])
	{
		for (int i = 0; i < x.length; i++)
			if (i < xData.size())
				xData.setElementAt(new Double(x[i]), i);

	}

	public Object getElementX(int i)
	{
		return xData.elementAt(i);
	}

	public Object getElementY(int i)
	{
		return yData.elementAt(i);
	}

	public void replaceYValueAt(int index, double newValue)
	{
		if (index < yData.size())
		{
			Vector tmp = new Vector();
			for (int i = 0; i < yData.size(); i++)
				if (index == i)
					tmp.addElement(new Double(newValue));
				else
					tmp.addElement(yData.elementAt(i));

			yData = tmp;
		}
	}

	public void replaceXValueAt(int index, double newValue)
	{
		if (index < xData.size())
		{
			Vector tmp = new Vector();
			for (int i = 0; i < xData.size(); i++)
				if (index == i)
					tmp.addElement(new Double(newValue));
				else
					tmp.addElement(xData.elementAt(i));

			xData = tmp;
		}
	}

	public void replaceXYValueAt(int index, double newValueX, double newValueY)
	{
		replaceXValueAt(index, newValueX);
		replaceYValueAt(index, newValueY);
	}

	protected String doubleToString(Double d)
	{
		if (valueFormat.compareTo("") == 0)
			return d.toString();
		DecimalFormat df = null;
		if (Chart.numberLocale == null)
		{
			df = new DecimalFormat(valueFormat);
		} else
		{
			NumberFormat nf = NumberFormat.getNumberInstance(new Locale(Chart.numberLocale, ""));
			df = (DecimalFormat)nf;
			df.applyPattern(valueFormat);
		}
		df = new DecimalFormat(valueFormat);
		return df.format(d.doubleValue());
	}
}
